package com.charging.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charging.common.annotation.Log;
import com.charging.common.core.controller.BaseController;
import com.charging.common.core.domain.AjaxResult;
import com.charging.common.enums.BusinessType;
import com.charging.system.domain.KxChargingScheme;
import com.charging.system.service.IKxChargingSchemeService;
import com.charging.common.utils.poi.ExcelUtil;
import com.charging.common.core.page.TableDataInfo;

/**
 * 充电规则Controller
 *
 * @author charging
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/system/scheme")
public class KxChargingSchemeController extends BaseController
{
    @Autowired
    private IKxChargingSchemeService kxChargingSchemeService;

    /**
     * 查询充电规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(KxChargingScheme kxChargingScheme)
    {
        startPage();
        List<KxChargingScheme> list = kxChargingSchemeService.selectKxChargingSchemeList(kxChargingScheme);
        return getDataTable(list);
    }

    /**
     * 导出充电规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:export')")
    @Log(title = "充电规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KxChargingScheme kxChargingScheme)
    {
        List<KxChargingScheme> list = kxChargingSchemeService.selectKxChargingSchemeList(kxChargingScheme);
        ExcelUtil<KxChargingScheme> util = new ExcelUtil<KxChargingScheme>(KxChargingScheme.class);
        util.exportExcel(response, list, "充电规则数据");
    }

    /**
     * 获取充电规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:query')")
    @GetMapping(value = "/{chargingSchemeId}")
    public AjaxResult getInfo(@PathVariable("chargingSchemeId") Long chargingSchemeId)
    {
        return success(kxChargingSchemeService.selectKxChargingSchemeByChargingSchemeId(chargingSchemeId));
    }

    /**
     * 新增充电规则
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:add')")
    @Log(title = "充电规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KxChargingScheme kxChargingScheme)
    {
        return toAjax(kxChargingSchemeService.insertKxChargingScheme(kxChargingScheme));
    }

    /**
     * 修改充电规则
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:edit')")
    @Log(title = "充电规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KxChargingScheme kxChargingScheme)
    {
        return toAjax(kxChargingSchemeService.updateKxChargingScheme(kxChargingScheme));
    }

    /**
     * 删除充电规则
     */
    @PreAuthorize("@ss.hasPermi('system:scheme:remove')")
    @Log(title = "充电规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargingSchemeIds}")
    public AjaxResult remove(@PathVariable Long[] chargingSchemeIds)
    {
        return toAjax(kxChargingSchemeService.deleteKxChargingSchemeByChargingSchemeIds(chargingSchemeIds));
    }
}
